<?php 
include('../Connections/KRAPPERCON.php');
include ("../Connections/Accesos.php");
?>
<div>
<input value="Registrar" type="button" onclick="grabarAnticipo()" />
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0" id="tbl_dat_ant">
  <tr>
    <td>Documento :</td>
    <td>
      <input name="t_at_ref" value="<?php echo getVal('documento');?>" type="text" id="t_at_ref" size="20" disabled="disabled" />
    </td>
  </tr>
  <tr>
    <td>Fecha Anticipo</td>
    <td>
      <input name="t_at_fec" value="<?php echo $hoy ?>" type="text" class="tcal" id="t_at_fec" size="15" maxlength="15">
    </td>
  </tr>
  <tr>
    <td>Monto Total :</td>
    <td>
<span id="sp_at_tot"><?php echo getVal('monto');?></span></td>
  </tr>
  <tr>
    <td>Monto Anticipo :</td>
    <td>
      <input name="t_at_mon" type="text" value="0" class="qt clsReq" id="t_at_mon" onChange="mr(this);valAntiChanged(this)" size="12" maxlength="15" />
    </td>
  </tr>
  <tr>
    <td>Texto</td>
    <td>
      <input name="t_at_txt" type="text" class="clsReq" id="t_at_txt" size="40" maxlength="40">
    </td>
  </tr>
  <tr>
    <td>Pendiente :</td>
    <td><span id="sp_at_pnd"></span></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>

<script type="text/javascript">
function valAntiChanged(obj){
var tot = pFloat(GEBI('sp_at_tot').innerHTML);
var pnd = tot - pFloat(obj.value);
GEBI('sp_at_pnd').innerHTML = myRound(pnd);
}

function grabarAnticipo(){
	if (!$("#tbl_dat_ant").checkInput()){
	return;
	}

	var monto = pFloat( GEBI('t_at_mon').value);
	var tot = pFloat(GEBI('sp_at_tot').innerHTML);
	if (monto > tot ) {
	showError('Monto de Anticipo supera del Valor de Venta Total del Documento');
	return;
	}
	if (monto < 1  ) {
	showError('Ingrese un Monto valido de Anticipo');
	return;
	}
	sendData('Procesos/Opers/OperAntic.php',
	{ 
	oper : 'add' , 
	documento : GEBI('t_at_ref').value, 
	monto : monto,
	fecha : GEBI('t_at_fec').value, 
	texto : GEBI('t_at_txt').value
	}	
	);
}
</script>